package org.doubango.FrCall.Screens;

import java.util.ArrayList;
import java.util.HashMap;

import org.doubango.FrCall.Engine;
import org.doubango.FrCall.R;
import org.doubango.FrCall.Services.IScreenService;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SimpleAdapter;

public class ScreenManageFriend extends BaseScreen {

	private static String TAG = ScreenChatSip.class.getCanonicalName();
	private final IScreenService mScreenService;
	
	private Button backToManageFriendSelectViewFromManageFriendView;
	private ListView manageFriendList;
	
	public ScreenManageFriend() {
		super(SCREEN_TYPE.MANAGE_FRIEND, TAG);
		mScreenService = ((Engine)Engine.getInstance()).getScreenService();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.screen_manage_friend);
		backToManageFriendSelectViewFromManageFriendView = (Button) findViewById(R.id.back_to_manage_friend_select_view_from_manage_friend_view);
		manageFriendList = (ListView) findViewById(R.id.manage_friend_list);
		
		backToManageFriendSelectViewFromManageFriendView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mScreenService.show(ScreenManageFriendSelect.class);
			}
		});
		HashMap<String, String> manageFriendMap = new HashMap<String, String>();
		manageFriendMap.put("ManagedFriendName", "王小二");
		manageFriendMap.put("ManagedFriendId", "ID:10874743908");
		ArrayList<HashMap<String, String>> manageFriendData = new ArrayList<HashMap<String,String>>();
		for(int i=0;i<10;i++){
			manageFriendData.add(manageFriendMap);
		}
		SimpleAdapter manageFriendAdapter = new SimpleAdapter(this, manageFriendData, R.layout.manage_friend_list_item, new String[]{"ManagedFriendName","ManagedFriendId"}, new int[]{R.id.managed_friend_name,R.id.managed_friend_id});
		manageFriendList.setAdapter(manageFriendAdapter);
	}
	
	public void deleteFriend(View v){
		Builder builder = new Builder(ScreenManageFriend.this);
		AlertDialog dialog = builder.create();
		dialog.setMessage("确认删除好友？");
		dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确认", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				
			}
		});
		dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				
			}
		});
		dialog.show();
	}
	
	public void groupFriend(View v){
		Builder builder = new Builder(ScreenManageFriend.this);
		AlertDialog dialog1 = builder.create();
		dialog1.setMessage("选择分组");
		View view = LayoutInflater.from(ScreenManageFriend.this).inflate(R.layout.dialog_list_group, null);
		ListView listGroup = (ListView) view.findViewById(R.id.dialog_list);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(ScreenManageFriend.this, android.R.layout.simple_list_item_1, new String[]{"同学", "家人", "发小", "情人"});
		listGroup.setAdapter(adapter);
		dialog1.setView(view);//addContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
		dialog1.show();
		listGroup.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Builder builder = new Builder(ScreenManageFriend.this);
				AlertDialog dialog2 = builder.create();
				dialog2.setMessage("确认将好友放入此分组？");
				dialog2.setButton(DialogInterface.BUTTON_POSITIVE, "确认", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						
					}
				});
				dialog2.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						
					}
				});
				dialog2.show();
			}
		});
	}
	

}
